import { query } from './config/database.js'

async function testQuery() {
  try {
    console.log('开始测试查询')
    
    // 测试最简单的查询
    const result = await query('SELECT * FROM matches WHERE id = 1')
    console.log('查询返回类型:', typeof result)
    console.log('查询返回是否数组:', Array.isArray(result))
    console.log('查询返回长度:', result.length)
    
    console.log('查询结果第一项类型:', typeof result[0])
    console.log('查询结果第一项:', result[0])
    
    if (result && result.length > 0 && result[0] && result[0].length > 0) {
      const matches = result[0]
      console.log('matches类型:', typeof matches)
      console.log('matches是否数组:', Array.isArray(matches))
      console.log('matches长度:', matches.length)
      
      const match = matches[0]
      if (match) {
        console.log('单个match:', match)
        console.log('home_school_id:', match.home_school_id)
        
        // 获取学校信息
        const schoolResult = await query('SELECT * FROM schools WHERE id = ?', [match.home_school_id])
        console.log('学校查询结果类型:', typeof schoolResult)
        console.log('学校查询结果第一项:', schoolResult[0])
      }
    } else {
      console.log('未找到匹配或结果结构不符合预期')
    }
  } catch (error) {
    console.error('测试查询失败:', error)
  }
}

testQuery() 